#pragma once

#include "cl_windowlistener.h"
/**
ClientSystem is responsible for everything that has to do with client side, eg. the interactive
part of the game. Client reads input from user, reads network packets from server and renders 
the whole scene and gui. 
**/
class ClientSystem:public Client, public Ogre::Singleton<ClientSystem>{
public:
	ClientSystem();
	~ClientSystem();
	/*
	=================================
	INTERFACE IMPLEMENTATION
	=================================
	*/
	///Initializes all client subsystems (ogre, gui, client networking)
	void	init();
	///Shuts down all client side systems
	void	shutdown();
	/// Runs entire client frame (includes rendering, reading from network, input, etc..)
	void	update();
	/// Returns false if windows has been closed (also when window is closed client is shut down)
	bool	isRunning();
	/// Initializes a connection to server
	void	connect(const char *host);
	/// Disconnects from a server
	void	disconnect();
	/*
	=================================
	INPUT CALLBACKS (Called from WindowListener)
	=================================
	*/
	void	onMouseMove(int relx, int rely);
	void	onMouseDown(int x, int y, int button);
	void	onMouseUp(int x, int y, int button);
	void	onKeyDown(int keycode, int text);
	void	onKeyUp(int keycode, int text);
	//just to resolve ambiguity
	inline static ClientSystem &getSingleton(){return *ms_Singleton;}
	inline static ClientSystem *getSingletonPtr(){return ms_Singleton;}
protected:
	void	initRenderer();
	void	initResources();
	void	initInput();
	void	render();
protected:
	//following need to be freed
	OIS::InputManager	*mInputSystem;
	OIS::Keyboard		*mKeyboard;
	OIS::Mouse			*mMouse;
	CGMain				*mGame;
	//everything below this point does not need to be freed
	OgreRootPtr			mOgreRoot;
	Ogre::RenderWindow	*mOgreWindow;
	Ogre::SceneManager	*mOgreScene;
	WindowListenerPtr	mWindowListener;
	///indicated if client system is running
	bool				mRunning;
};